package com.egghiro.framework.j2se.util;

import java.util.Iterator;

public class SIterator<E> implements Iterator<E> {
    private Iterator<E> iterator;
    /*
     * 如果采用SIterator实现IterateRemover的方法，
     * 在实际调用中可以把IterateRemover强转成SIterator而获得其全部功能
     * 采用内部类的回调技术，可以保证调用中获得了IterateRemover也不能干多余的事
     */
    private IterateRemover itRemover = new IterateRemover() {
        public void remove() {
            SIterator.this.remove();
        }
    };

    public SIterator(Iterator<E> iterator) {
        this.iterator = iterator;
    }

    public boolean hasNext() {
        return iterator.hasNext();
    }

    public E next() {
        return iterator.next();
    }

    public void remove() {
        iterator.remove();
    }

    public IterateRemover getRemover() {
        return itRemover;
    }

}
